import 'dart:io' show Platform;

import 'package:example/app.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'
    show PlatformDispatcher, debugDefaultTargetPlatformOverride;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show DeviceOrientation, SystemChrome;
import 'package:provider/provider.dart';

import 'provider/app_provider.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  _setTargetPlatformForDesktop();
  SystemChrome.setPreferredOrientations(<DeviceOrientation>[
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]).then((_) {
    runApp(
      ChangeNotifierProvider<AppProvider>.value(
        value: AppProvider(
          brightness: PlatformDispatcher.instance.platformBrightness,
        ),
        child: App(),
      ),
    );
  });
}

/// 适配桌面客户端，mac用ios，windows，linux用android
void _setTargetPlatformForDesktop() {
  TargetPlatform? targetPlatform; // 改为可空类型
  if (Platform.isMacOS) {
    targetPlatform = TargetPlatform.iOS;
  } else if (Platform.isLinux || Platform.isWindows) {
    targetPlatform = TargetPlatform.android;
  } else if (Platform.isAndroid){
    targetPlatform = TargetPlatform.android;
  } else if (Platform.isOhos){
    print("====== ohos");
    targetPlatform = TargetPlatform.ohos;
    print("====== ohos success");
  }

  print("====== targetPlatform is what");
  // 只有在非空时才设置
  // if (targetPlatform != null) {
  //   print("====== targetPlatform: 11 $targetPlatform");
  //   debugDefaultTargetPlatformOverride = targetPlatform;
  //   print("====== targetPlatform: 22");
  // }
  print("====== targetPlatform: $targetPlatform");
}